home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 3_0 / DELTASOU / DELTASOU.C < prev   
C/C++ Source or Header  |  1989-09-16  |  3KB  |  152 lines

  1. /*
  2. >>    DeltaSound.c
  3. >>    Copyright ⌐1989, Juri Munkki
  4. >>
  5. >>    Takes any file and modifies the data fork
  6. >>    so that sound files compress to smaller
  7. >>    files. Forward process is called "differentiate"
  8. >>    and backward "integrate".
  9. */
  10.  
  11. SFReply        reply;
  12. int            direction;
  13.  
  14. /*
  15. >>    All the actual work is done inside this
  16. >>    filter procedure. If the user opens a file,
  17. >>    we open a working directory, and then
  18. >>    process the file according to the direction
  19. >>    flag. 0 is forward, anything else is back.
  20. */
  21. pascal    int        FilterProc(item,dialog)
  22. int            item;
  23. DialogPtr    dialog;
  24. {
  25.                 int            refnum;
  26.                 char        buffer[16384];
  27.                 WDPBRec        dir;
  28.     register    char        *from,*to,old,new;
  29.     register    long        looper;
  30.                 long        mark,len;
  31.                 DialogPtr    message;
  32.                 int            theerr;
  33.  
  34.     if(item==getOpen)    /*    Is Open button hit?    */
  35.     {    /*    Tell the user that work is being done!    */
  36.         SetCursor(*GetCursor(watchCursor));
  37.         message=GetNewDialog(1001,0,-1);
  38.         DrawDialog(message);
  39.         
  40.         dir.ioCompletion=0;            /*    See relevant technotes and    */
  41.         dir.ioNamePtr=0;            /*    Inside Macintosh chapters    */
  42.         dir.ioVRefNum=-SFSaveDisk;    /*    for information on why and    */
  43.         dir.ioWDProcID='ERIK';        /*    how we open a working        */
  44.         dir.ioWDDirID=CurDirStore;    /*    directory.                    */
  45.         theerr=PBOpenWD(&dir,0);
  46.  
  47.         reply.vRefNum=dir.ioVRefNum;
  48.  
  49.         FSOpen(reply.fName,reply.vRefNum,&refnum);
  50.  
  51.         old=128;    /*    First value can be anything    */
  52.         do
  53.         {    len=16384;
  54.             GetFPos(refnum,&mark);
  55.             FSRead(refnum,&len,buffer);
  56.             if(len>0)
  57.             {    from=to=buffer;
  58.                 if(direction)
  59.                 {    asm    {
  60.                         move.w    #16383,looper
  61.  
  62.                 @intg    move.b    (from)+,new
  63.                         sub.b    new,old
  64.                         move.b    old,(to)+
  65.                         dbra    looper,@intg
  66.                         }
  67.                 }
  68.                 else
  69.                 {    asm    {
  70.                         move.w    #16383,looper
  71.                 @dif    move.b    (from)+,new
  72.                         sub.b    new,old
  73.                         move.b    old,(to)+
  74.                         move.b    new,old
  75.                         dbra    looper,@dif
  76.                         }
  77.                 }
  78.                 SetFPos(refnum,fsFromStart,mark);
  79.                 FSWrite(refnum,&len,buffer);
  80.             }
  81.         }    while(len==16384);
  82.         FSClose(refnum);
  83.         FlushVol(0L,reply.vRefNum);
  84.  
  85.         item=100;
  86.         DisposDialog(message);
  87.         SetCursor(&arrow);
  88.     }
  89.  
  90.     return item;
  91. }
  92.  
  93. /*
  94. >>    Some users like to use the keyboard for quitting
  95. >>    and buttons. This simple procedure defines some
  96. >>    shortcuts. I would not write anything like this
  97. >>    into a real application. Real applications use
  98. >>    resources so that the user can edit the shortcuts.
  99. */
  100. pascal    int        keyfilter(theDialog,theEvent,itemHit)
  101. DialogPtr    theDialog;
  102. EventRecord    *theEvent;
  103. int            *itemHit;
  104. {
  105.     if(theEvent->what==keyDown && (theEvent->modifiers & cmdKey))
  106.     {    switch((char)theEvent->message)
  107.         {    case 'Q':
  108.             case 'q':
  109.             case '.':
  110.                 *itemHit=2;
  111.                 break;
  112.             case 'D':
  113.             case 'd':
  114.                 *itemHit=3;
  115.                 break;
  116.             case 'I':
  117.             case 'i':
  118.                 *itemHit=4;
  119.                 break;
  120.             default:
  121.                 *itemHit=0;
  122.         }
  123.         return -1;
  124.     }
  125.     return 0;
  126. }
  127. void    main()
  128. {
  129.     DialogPtr    thedia;
  130.     int            thehit;
  131.     int            zerostring=0;
  132.     
  133.     InitGraf(&thePort);        InitCursor();
  134.     InitFonts();            InitWindows();
  135.     InitMenus();            TEInit();
  136.     InitDialogs(0L);
  137.     
  138.     thedia=GetNewDialog(1000,0,-1);
  139.     do
  140.     {    ModalDialog(keyfilter,&thehit);
  141.         switch(thehit)
  142.         {    case 3:
  143.                 direction=0;
  144.                 SFGetFile(0x00400048L,&zerostring,0L,-1,0L,FilterProc,&reply);
  145.                 break;
  146.             case 4:
  147.                 direction=1;
  148.                 SFGetFile(0x00400048L,&zerostring,0L,-1,0L,FilterProc,&reply);
  149.                 break;
  150.         }
  151.     }    while(thehit!=2);
  152. }